package com.anyou.mall.fin.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.utils.DateUtils;
import com.anyou.mall.fin.vo.GetTotalVo;
import com.anyou.mall.fin.vo.TrendChartVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.fin.mapper.PlatformReconciliationMapper;
import com.anyou.mall.fin.domain.PlatformReconciliation;
import com.anyou.mall.fin.service.IPlatformReconciliationService;

/**
 * 平台对账Service业务层处理
 *
 * @author gaochaohao
 * @date 2022-04-19
 */
@Service
public class PlatformReconciliationServiceImpl extends ServiceImpl<PlatformReconciliationMapper,PlatformReconciliation> implements IPlatformReconciliationService
{
    @Autowired
    private PlatformReconciliationMapper platformReconciliationMapper;

    @Autowired
    private IPlatformReconciliationService platformReconciliationService;

    /**
     * 查询平台对账
     *
     * @param platformReconciliationId 平台对账主键
     * @return 平台对账
     */
    @Override
    public PlatformReconciliation selectPlatformReconciliationByPlatformReconciliationId(Long platformReconciliationId)
    {
        return platformReconciliationMapper.selectPlatformReconciliationByPlatformReconciliationId(platformReconciliationId);
    }

    /**
     * 查询平台对账列表
     *
     * @param platformReconciliation 平台对账
     * @return 平台对账
     */
    @Override
    public List<PlatformReconciliation> selectPlatformReconciliationList(PlatformReconciliation platformReconciliation)
    {
        return platformReconciliationMapper.selectPlatformReconciliationList(platformReconciliation);
    }

    /**
     * 新增平台对账
     *
     * @param platformReconciliation 平台对账
     * @return 结果
     */
    @Override
    public int insertPlatformReconciliation(PlatformReconciliation platformReconciliation)
    {
        platformReconciliation.setCreateTime(DateUtils.getNowDate());
        return platformReconciliationMapper.insertPlatformReconciliation(platformReconciliation);
    }

    /**
     * 修改平台对账
     *
     * @param platformReconciliation 平台对账
     * @return 结果
     */
    @Override
    public int updatePlatformReconciliation(PlatformReconciliation platformReconciliation)
    {
        platformReconciliation.setUpdateTime(DateUtils.getNowDate());
        return platformReconciliationMapper.updatePlatformReconciliation(platformReconciliation);
    }

    /**
     * 批量删除平台对账
     *
     * @param platformReconciliationIds 需要删除的平台对账主键
     * @return 结果
     */
    @Override
    public int deletePlatformReconciliationByPlatformReconciliationIds(Long[] platformReconciliationIds)
    {
        return platformReconciliationMapper.deletePlatformReconciliationByPlatformReconciliationIds(platformReconciliationIds);
    }

    /**
     * 删除平台对账信息
     *
     * @param platformReconciliationId 平台对账主键
     * @return 结果
     */
    @Override
    public int deletePlatformReconciliationByPlatformReconciliationId(Long platformReconciliationId)
    {
        return platformReconciliationMapper.deletePlatformReconciliationByPlatformReconciliationId(platformReconciliationId);
    }

    @Override
    public ApiResult<GetTotalVo> getTotal() {
        GetTotalVo getTotalVo = new GetTotalVo(new BigDecimal(0),new BigDecimal(0),new BigDecimal(0));
        //查询较昨日进账与出账
        String startTime=DateUtils.getDate()+" 00:00:00";
        String endTime=DateUtils.getDate()+" 23:59:59";
        GetTotalVo getTotalVo1 = platformReconciliationMapper.getComeTotal(startTime,endTime);
        if (getTotalVo1 != null) {
            BeanUtils.copyProperties(getTotalVo1,getTotalVo);
        }
        //查询资金池总额
        GetTotalVo getTotalVo2 = platformReconciliationMapper.getTotal();
        if (getTotalVo2 != null) {
            getTotalVo.setTotalCapital(getTotalVo2.getTotalCapital());
        }
        return ApiResult.success(getTotalVo);
    }

    @Override
    public ApiResult<List<TrendChartVo>> trendChart(String selectTime) {

        List<TrendChartVo> trendChartVoList = platformReconciliationMapper.getTrendChart(selectTime);
        return ApiResult.success(trendChartVoList);
    }
}
